package com.immediatus;

import android.view.View;
import com.immediatus.engine.Engine;
import com.immediatus.engine.contracts.IResolutionPolicy;
import com.immediatus.engine.input.TouchEvent;
import com.immediatus.engine.layer.Canvas;
import com.immediatus.graphics.camera.Camera;
import com.immediatus.logic.MainScreen;
import com.immediatus.options.EngineOptions;
import com.immediatus.ui.BaseActivity;
import com.immediatus.ui.view.RenderView;


public class MainActivity extends BaseActivity implements Canvas.IOnCanvasTouchListener{
    private static final int CAMERA_WIDTH = 480;
    private static final int CAMERA_HEIGHT = 800;

    private final Camera _camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
    private final Canvas _canvas = new Canvas();
    private final MainScreen _mainScreen = new MainScreen(this);

    @Override
    public Engine onLoadEngine(){
        return new Engine(new EngineOptions(true, EngineOptions.ScreenOrientation.PORTRAIT, new IResolutionPolicy() {
            @Override
            public void onMeasure(RenderView renderSurfaceView_, int w_, int h_){
                final int specWidth = View.MeasureSpec.getSize(w_);
                final int specHeight = View.MeasureSpec.getSize(h_);
                renderSurfaceView_.setMeasuredDimensionProxy(specWidth, specHeight);
            }
        }, this._camera));
    }

    @Override
    public void onLoadResources(){
        _mainScreen.loadResources();
    }

    @Override
    public Canvas onLoadLayer(){

        _mainScreen.initLayer(_canvas);

        _canvas.setOnTouchListener(this);
        _canvas.setTouchAreaBindingEnabled(true);
        return _canvas;
    }

    @Override
    public void onLoadComplete(){

    }

    @Override
    public boolean onTouchEvent(final Canvas canvas_, final TouchEvent event_){
        switch (event_.getAction()){
            case TouchEvent.ACTION_DOWN:
                break;
            case TouchEvent.ACTION_UP:
                break;
        }
        return true;
    }
}
